<!doctype html>
<html>

	<head>
		<title>选择出行日期</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="assets/css/amazeui.min.css">
		<link rel="stylesheet" type="text/css" href="assets/css/zabuto_calendar.css"/>
		<link rel="stylesheet" href="assets/css/style.css">
		<link rel="stylesheet" href="assets/css/bootstrap.min.css" />
		<!--<link rel="stylesheet" href="assets/css/dcalendar.picker.css" />-->
		<style>
			table thead tr {
				height: 30px;
				line-height: 30px;
			}
			
			table {
				width: 100%;
			}
			
			table td {
				width: 14.28%;
				position: relative;
			}
			/*.event_span{
				position:absolute;
				bottom: -6%;
				left: 29%;
				color:cadetblue;
			}*/
			.badge{
				white-space:pre-wrap;
				 word-wrap:break-word; 
			}
			.badge-event{
				
				line-height: 1.5rem;
				top:0%;
			}
			.turn_white div span{
				color:#fff!important;
			}
			/*.badge-event::after{
				font-size:1rem;
				content: "￥4444";
				position:absolute;
				left:-7%;
				top:58%;
			}*/
			.calendar-dow{
				line-height:2.5;
			}
		</style>
	</head>

	<body>
		<div class="containter">
			<header data-am-widget="header" class="am-header am-header-default">
				<div class="am-header-left am-header-nav">
					<a class="jump_to_show">
						<img src="assets/images/left.png">
					</a>
				</div>
				<h1 class="am-header-title">
      选择出行日期
    </h1>
			</header>
			<div style="height: 4rem"></div>
			
			<!--<table id='mycalendar' class='calendar'></table>-->
			<table id="my-calendar" class="containter"></table>
			<!-- <div id="content-wrapper">
    <div class="inner clearfix">
      <div id = 'calendar'>
      </div>
    </div>
    <div class="clear"></div>
  </div> -->
			<div class="timee" style="padding-bottom: 4rem;">
				<p class="time_p1"><img src="assets/images/tu2.png"><b>2017-04-25</b><span>库存 <b style="font-weight: 900;color:black"> 0</b></span></p>
				<p class="time_p2"><img src="assets/images/tu1.png">出行人数</p>

				<ul class="price_list">
					<!-- <li>
        <font>老人（65-80）￥4456</font>/人
        <div class="shuzi">
          <button type="button" class="minus">-</button>
          <input type="text" class="am-num-text" value="0" />
          <button type="button" class="plus">+</button>
        </div>
      </li> -->
					<!--<li>
						<font>成人（18-64）￥<span id="adult_price">4456</span></font>/人
						<div class="shuzi">
							<button type="button" class="minus change_btn">-</button>
							<input type="text" readonly="true" onkeydown="return false" class="am-num-text" value="0" id="adult_inpt"/>
							<button type="button" class="plus change_btn">+</button>
						</div>
					</li>-->
					<!-- <li>
        <font>儿童（占床）（12-17）￥4456</font>/人
        <div class="shuzi">
          <button type="button" class="minus">-</button>
          <input type="text" class="am-num-text" value="0" />
          <button type="button" class="plus">+</button>
        </div>
      </li> -->
					<!--<li>
						<font>儿童（2-11）￥<span id="child_price">4456</span></font>/人
						<div class="shuzi">
							<button type="button" class="minus change_btn">-</button>
							<input readonly="true" type="text" onkeydown="return false" class="am-num-text" value="0" id="child_inpt"/>
							<button type="button" class="plus change_btn">+</button>
						</div>
					</li>-->
					<!-- <li>
        <font>婴儿（0-1）￥4456</font>/人
        <div class="shuzi">
          <button type="button" class="minus">-</button>
          <input type="text" class="am-num-text" value="0" />
          <button type="button" class="plus">+</button>
        </div>
      </li> -->
				</ul>
				<div><img src="assets/images/a12.png" alt="">最少一人起订，订单最终价格以确定出游方案为准</div>
				<div class="Select-footer">
					总价：
					<font id="total_price">￥0</font><button id="sub_btn">填写订单</button>
				</div>
			</div>
			<script>
				
			</script>
			<script src="assets/js/jquery.min.js"></script>
			<script>
				//日历插件
//				$(document).ready(function () {
//					
//			       
//			    });
			</script>
			<!--<script type="text/javascript" src="assets/js/dcalendar.picker.js"></script>-->
			<script src="assets/js/zabuto_calendar.js"></script>
			<script src="assets/js/allUse.js"></script>
			<!--8.2可选团期-->
			<script type="text/javascript">
//				var possibleDate;
				if(window.sessionStorage.getItem("show_session")){
					var objs=JSON.parse(window.sessionStorage.getItem("show_session"));
					var line_id=objs.line_id;
					var title_name=objs.title_name;
					$(".jump_to_show").click(function(){
						window.location.href="show.html?line_id="+line_id
					})
//					var line_id=GetQueryString("line_id");
				}
				
//				$('#mydatepicker').dcalendarpicker();
//				$('#mydatepicker').dcalendarpicker({
//					format: 'yyyy-mm-dd',
//					
//				});
				
				
//				reMove()
//				function reMove(){
//					
//					$("tbody span").each(function(){
//						$(this).attr("id",$(this).html())
//					})
//					$(".pMDate span").remove()
//					$(".nMDate span").remove()	
//					
//				};
//				
//				$("#next").click(function(){
//					reMove();
//					
//				})
//				$("#prev").click(function(){
//					reMove();
//				})
//				$('#mycalendar').dcalendar({
//
//						});
				//可选团期;
				$(document).ready(function(){
					window.sessionStorage.removeItem("customer_list");//清除游客信息
					$.ajax({
					type: "post",
					//url: url_enter+"/api/get_enable_team",
					url: url_enter+"/apk/get_enable_team",
					headers: {
						"User-Token":token,
						"Os":ios_Andriod,
						"Device-Id":"",
						"Screen":wh,
						"Content-Type": "application/x-www-form-urlencoded"
					},
					data: {
						// “line_id”:1,//线路ID序列号，整数类型（Int）
						'line_id':line_id
					},
					success:function(data){					
						console.log(data)
						//价格列表展示
						var id_inpt;
						for(var i=0;i<data.data.enable_team_list[0].price_mes.length;i++){
							//i==0?id_inpt='baby':i==1?id_inpt='child':i==2?id_inpt='adult':id_inpt='elder';
							if(data.data.enable_team_list[0].price_mes[i].ptype==1){
			       				id_inpt="child";
			       			}else if(data.data.enable_team_list[0].price_mes[i].ptype==0){
			       				id_inpt="baby"
			       			}else if(data.data.enable_team_list[0].price_mes[i].ptype==3){
			       				id_inpt="adult"
			       			}else if(data.data.enable_team_list[0].price_mes[i].ptype==4){
			       				id_inpt="elder"
			       			}
						       		
							$('.price_list').append('<li ptype='+data.data.enable_team_list[0].price_mes[i].ptype+'><font>'+data.data.enable_team_list[0].price_mes[i].name+'￥<span id="'+id_inpt+'_price">'
							            +data.data.enable_team_list[0].price_mes[i].mprice+'</span></font>/人<div class="shuzi"><button type="button" class="minus change_btn">-</button><input readonly="true" type="text" onkeydown="return false" class="am-num-text" value="0" id="'+id_inpt+'_inpt"/> <button type="button" class="plus">+</button></div></li>')
						}
						
						//日历展示
						myDate=data;
						var arrTime=data.data.enable_team_list[0].time_day.split("-")
						var newArr=arrTime[0]+"年"+arrTime[1]+"月";
						var eventDate=[];
						var str=""
						for(var i=0;i<data.data.enable_team_list.length;i++){
//							console.log(data.data.enable_team_list[i].time_day.substring(5,10))
							eventDate.push({"date":data.data.enable_team_list[i].time_day,"badge":true})
							str+='#zabuto_calendar__'+data.data.enable_team_list[i].time_day+'_day .badge-event::after{font-size:1rem;content: "￥'+data.data.enable_team_list[i].price_mes[2].mprice+'";text-align:center;}'
						};
						$("head").append('<style>'+str+'</style>');
//						$（ '＃mydatepicker'）dcalendarpicker（）。//创建日期选择器
//						$('#mycalendar').dcalendar({
//						}); //创建日历
						//日历控件
//						console.log(eventDate);
						var enable_time="";
						var years=arrTime[0];
						var month=arrTime[1];
						if(objs.enable_time){
							enable_time=objs.enable_time;
							years=enable_time.substring(0,4);
							month=enable_time.substring(5,7);
						};
						
						$("#my-calendar").zabuto_calendar({
				        	language: 'zi',
				        	year:years,
				        	month:month,
				        	type:"block",
				        	cell_border: true,
				        	show_previous:true,
				        	show_previous:true,
				        	data:eventDate,
				        	action: function () {
				                return myDateFunction(this.id, false);
				            },
				       	});
				       	if(enable_time){
				       		$("#zabuto_calendar__"+enable_time+"_day").trigger("click");
				       	}else{
				       		
				       		$(".badge").eq(0).parent().parent().trigger("click");
				       	};
				       	changePrice();
				       	$(".minus").click(function() {
							var t = $(this).parent().find('.am-num-text');
							t.val(parseInt(t.val()) - 1);
							if(t.val() <= 0) {
								t.val(0);
							}
							changePrice()
//									TotalPrice();
						});
						// 数量加
						$(".plus").click(function(){
							//var other_num=parseInt($(".plus").eq(1).parent().find($("input")).val());
							var t_num=0;
							$(".plus").parent().find($("input")).each(function(i,v){
    							t_num+=parseInt($(v).val())
							})
							var this_num=parseInt($(this).parent().find($("input")).val());
							//if((other_num+this_num)>=$(".time_p1 span b").html()){
							if((t_num)>=$(".time_p1 span b").html()){
								return;
							}else{
								$(this).parent().find($("input")).val(parseInt($(this).parent().find($("input")).val())+1);
								changePrice()
							}
						});
//						$(".plus").eq(1).click(function(){
//							//var other_num=parseInt($(".plus").eq(0).parent().find($("input")).val());
//							var this_num=parseInt($(this).parent().find($("input")).val());
//							if((other_num+this_num)>=$(".time_p1 span b").html()){
//								return;
//							}else{
//								$(this).parent().find($("input")).val(parseInt($(this).parent().find($("input")).val())+1);
//								changePrice()
//							}
//						})
						var index;
						var team_id;
				       	 function myDateFunction(id, fromModal) {					        
					        var date = $("#" + id).data("date");
					        var hasEvent = $("#" + id).data("hasEvent");
//					        consdateole.log($("#" + id).data())
					        if (hasEvent) {
					        	 $("td").css({"background":"#fff"});
					       		 $("#" + id).css({"background":"#68bae0"});
					       		 $("td").removeClass("turn_white");
					       		 $("#" + id).addClass("turn_white");
					        	 $(".time_p1 b").html(date);
					        	 
					        	//改变成人价格
					        	for(var j=0;j<data.data.enable_team_list.length;j++){
				       			if(data.data.enable_team_list[j].time_day==$("#" + id).data("date")){
				       				index=j
				       				$(".time_p1 b").html(""+data.data.enable_team_list[j].time_day+"");
						       		$(".time_p1 span b").html(data.data.enable_team_list[j].stock)
						       		for(var k=0;k<data.data.enable_team_list[j].price_mes.length;k++){
						       			if(data.data.enable_team_list[j].price_mes[k].ptype==0){
						       				$("#baby_price").html(""+(data.data.enable_team_list[j].price_mes[k].mprice||0)+"")
						       			}else if(data.data.enable_team_list[j].price_mes[k].ptype==1){
						       				$("#child_price").html(""+(data.data.enable_team_list[j].price_mes[k].mprice||0)+"")
						       			}else if(data.data.enable_team_list[j].price_mes[k].ptype==3){
						       				$("#adult_price").html(""+(data.data.enable_team_list[j].price_mes[k].mprice||0)+"")
						       			}else if(data.data.enable_team_list[j].price_mes[k].ptype==4){
						       				$("#elder_price").html(""+(data.data.enable_team_list[j].price_mes[k].mprice||0)+"")
						       			}
						       		}
//						       		$("#adult_price").html(""+(data.data.enable_team_list[j].price_mes[2].mprice||0)+"")
//						       		$("#child_price").html(""+(data.data.enable_team_list[j].price_mes[1].mprice||0)+"")
//						       		$("#baby_price").html(""+(data.data.enable_team_list[j].price_mes[0].mprice||0)+"")
//						       		$("#elder_price").html(""+(data.data.enable_team_list[j].price_mes[3].mprice||0)+"")
						       		var total_price;
						       		team_id=data.data.enable_team_list[j].team_id;
						       		// 数量减
//									TotalPrice();
//									function TotalPrice() {
//										var oprice = 0;
//										$(".GoodsCheck").each(function() {
//											if($(this).is(":checked")) {
//												var price = parseFloat($(this).parents(".one-goods").find(".GoodsPrice").text());
//												var num = parseInt($(this).parents(".one-goods").find(".am-num-text").val());
//												var total = price * num;
//												oprice += total;
//											}
//											$(".ShopTotal").text(oprice.toFixed(2));
//										});
//									}
				       			}
				       	};
					        	changePrice()
					        }
					        return true;
					    };
					    function changePrice(){
					    	var bap=0,chp=0,adp=0,elp=0;
					    	for(var k=0;k<data.data.enable_team_list[index].price_mes.length;k++){
				       			if(data.data.enable_team_list[index].price_mes[k].ptype==1){
				       				 chp=data.data.enable_team_list[index].price_mes[k].mprice
				       			}else if(data.data.enable_team_list[index].price_mes[k].ptype==0){
				       				bap=data.data.enable_team_list[index].price_mes[k].mprice
				       			}else if(data.data.enable_team_list[index].price_mes[k].ptype==3){
				       				adp=data.data.enable_team_list[index].price_mes[k].mprice
				       			}else if(data.data.enable_team_list[index].price_mes[k].ptype==4){
				       				elp=data.data.enable_team_list[index].price_mes[k].mprice
				       			}
				       		}
					    	var baby_num=$("#baby_inpt").val()||0;
			       			var adult_num=$("#adult_inpt").val()||0;
			       			var child_num=$("#child_inpt").val()||0;
			       			var elder_num=$("#elder_inpt").val()||0;
			       			total_price=adult_num*adp+child_num*chp
			       						+baby_num*bap+elder_num*elp
			       			$("#total_price").html("￥"+total_price);
			       		}
			       		$("#sub_btn").click(function(){
			       			var dePartDay=data.data.enable_team_list[index].time_day;//出发日期
			       			var stock=data.data.enable_team_list[index].stock;//库存
			       			//var total_num=parseFloat($("#adult_inpt").val())+parseFloat($("#child_inpt").val())+parseFloat($("#baby_inpt").val())+parseFloat($("#elder_inpt").val());//出行人数
			       			var adult_price=$("#adult_price").html()||0;
			       			var child_price=$("#child_price").html()||0;
			       			var baby_price=$("#baby_price").html()||0;
			       			var elder_price=$("#elder_price").html()||0;
			       			var adult_num=$("#adult_inpt").val()||0;
			       			var child_num=$("#child_inpt").val()||0;
			       			var baby_num=$("#baby_inpt").val()||0;
			       			var elder_num=$("#elder_inpt").val()||0;
			       			var total_num=parseInt(adult_num) + parseInt(child_num)+parseInt(baby_num)+parseInt(elder_num);
			       			console.log(dePartDay);
			       			if(total_num===0){
			       				alert("请确定出行人数");
			       				return;
			       			}else if((parseInt(adult_num)===0&&parseInt(elder_num)===0) && (parseInt(child_num)>0||parseInt(baby_num)>0)){
			       				alert("儿童需在成人陪同下出行！");
			       				return;
			       			};
							var arr={
								"dePartDay":""+dePartDay+"",
								"stock":""+stock+"",
								"total_num":""+total_num+"",
								"baby_price":""+baby_price+"",
								"elder_price":""+elder_price+"",
								"adult_price":""+adult_price+"",
								"child_price":""+child_price+"",
								"line_id":""+line_id+"",
								"baby_num":""+baby_num+"",
								"elder_num":""+elder_num+"",
								"adult_num":""+adult_num+"",
								"child_num":""+child_num+"",
								"title_name":""+title_name+"",
								"total_price":""+total_price+"",
								"team_id":""+team_id+"",
							};
			       			sessionStorage.setItem("form_option_date",encodeURIComponent(JSON.stringify(arr)));
			       			window.location.href="information.html";
			       			console.log(sessionStorage.getItem("form_option_date"));
			       			console.log(decodeURIComponent(sessionStorage.getItem("form_option_date")));
			       			console.log(JSON.parse(decodeURIComponent(sessionStorage.getItem("form_option_date"))))
			       		});
					}
				})
				})
				
			</script>
	</body>
</html>